package nccu.model;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import org.compass.annotations.Searchable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import java.io.Serializable;

/**
 * This class is used to represent an cycle;
 *
 * @author <a href="mailto:chris.oberle@gmail.com">Chris Oberle</a>
 */
@Embeddable
@Searchable(root = false)
public class Cycle extends BaseObject implements Serializable {
     private static final long serialVersionUID = 3617859655330969241L;

     @XStreamAlias("Month")
     private Integer month;

     @XStreamAlias("Year")
     private Integer year;

    public Cycle(){}

    @Column(name = "month", length = 15)
    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    @Column(name = "year", length = 15)
    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Cycle)) return false;

        Cycle cycle = (Cycle) o;

        if (!month.equals(cycle.month)) return false;
        if (!year.equals(cycle.year)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = month.hashCode();
        result = 31 * result + year.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "Cycle{" +
                "month='" + month + '\'' +
                ", year='" + year + '\'' +
                '}';
    }
}
